package com.icemelon.catdog.controller;

import com.icemelon.catdog.pojo.Pet;
import com.icemelon.catdog.pojo.PetCatagory;
import com.icemelon.catdog.pojo.PetCatagoryExample;
import com.icemelon.catdog.pojo.PetDetails;
import com.icemelon.catdog.service.PetService;
import com.icemelon.catdog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class PetdateController {
    @Autowired
    private PetService petService;
    /**
     * 业务需求：根据宠物id查询宠物信息
     * url地址/pets
     * 类型：
     * 参数id：昵称，性别，年龄，物种，品种，颜色，体型，描述
     * 返回值：
     * {state,message,data}
     */
        @RequestMapping("/findPetById")
    public Result findPetById(Integer id){
            Pet pet = petService.findPetById(id);
            if (pet==null){
                return Result.fail("没有查询到这个");
            }
            return Result.success(pet);
        }
    /**
     * 查询宠物详细信息
     *
     */
    @RequestMapping("/petDetails")
    public Result findByIds(Integer id){
        PetDetails pet=petService.findPetByIds(id);
        if (pet==null){
            Result.fail("这条宠物没有详细信息");
        }
        return Result.success(pet);
    }

    /**
     * 新增宠物信息
     * @return
     */
    @RequestMapping("/save")
    public Result savePet(Pet pet, PetDetails petDetails){
         petService.savePet(pet,petDetails);
         return Result.success(pet);
    }
    /**
     * 删除宠物信息
     */
    @RequestMapping("/delete")
    public Result deletePets(Integer... ids){
        petService.deletePets(ids);
        if(ids==null){
            return Result.fail("没有这条宠物");
        }
        return Result.success();

    }
    /**
     * 修改宠物信息
     */
    @RequestMapping("/update")
    public Result updatePet(Pet pet, PetDetails petDetails){
        petService.updatePet(pet,petDetails);
        return Result.success(pet);
    }
}
